package com.hh.eduservice.controller;


import com.hh.commonutils.Result;
import com.hh.eduservice.entity.EduChapter;
import com.hh.eduservice.entity.EduVideo;
import com.hh.eduservice.entity.chapter.ChapterVo;
import com.hh.eduservice.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author huhuan
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
public class EduChapterController {
    @Autowired
    private EduChapterService eduChapterService;

    @GetMapping("/getChapterById/{courseId}")
    public Result getChapterbyId(@PathVariable String courseId){
        List<ChapterVo> chapters = eduChapterService.getChapterById(courseId);
        return Result.success().data("chapters",chapters);
    }

    @PostMapping("/addChapter")
    public Result addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.addChapter(eduChapter);
        return Result.success();
    }

    @DeleteMapping("deleteChapterById/{chapterId}")
    public Result deleteChapterById(@PathVariable String chapterId){
        eduChapterService.removeChapterById(chapterId);

        return Result.success().data("msg","删除成功!");
    }

    @PostMapping("/updateById")
    public Result updateById(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return Result.success();
    }

    @GetMapping("/getEduChapterById/{chapterId}")
    public Result getEduChapterById(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.getEduChapterById(chapterId);
        return Result.success().data("eduChapter",eduChapter);
    }

}
